package com.examiner.service.impl;

import com.examiner.bean.test.NewTest;
import com.examiner.bean.test.NewTestUser;
import com.examiner.bean.test.TestDB;
import com.examiner.bean.vo.MyTestAndTestDBVo;
import com.examiner.dao.NewTestDao;
import com.examiner.dao.NewTestUserDao;
import com.examiner.dao.TestDBDao;
import com.examiner.page.QueryInfo;
import com.examiner.service.CheckTestService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class CheckTestServiceImpl implements CheckTestService {

    @Resource
    private NewTestUserDao newTestUserDao;

    @Resource
    private TestDBDao testDBDao;

    @Resource
    private NewTestDao newTestDao;

    @Override
    public List<MyTestAndTestDBVo> getCheckTestList(Integer id, QueryInfo queryInfo) throws Exception{
        List<MyTestAndTestDBVo> list = new ArrayList<>();
        MyTestAndTestDBVo myTestAndTestDBVo;
        List<NewTestUser> myTestList = newTestUserDao.findCheckTestList(id, (queryInfo.getPageNum() - 1) * queryInfo.getPageSize(), queryInfo.getPageSize(), queryInfo.getQuery());
        if (myTestList.size() != 0){
            for (NewTestUser newTestUser : myTestList) {
                myTestAndTestDBVo = new MyTestAndTestDBVo();
                TestDB one = testDBDao.getOne(newTestUser.getTid());
                NewTest one1 = newTestDao.getOne(newTestUser.getNid());
                myTestAndTestDBVo.setTestDB(one);
                myTestAndTestDBVo.setNewTestUser(newTestUser);
                myTestAndTestDBVo.setNewTest(one1);
                list.add(myTestAndTestDBVo);
            }
        }
        return list;
    }

    @Override
    public int getCheckTestListTotal(Integer id, QueryInfo queryInfo) throws Exception {
        return newTestUserDao.findCheckTestListTotal(id,queryInfo.getQuery());
    }
}
